******************************************************************************************
* Do-file name:	an_reg_wage_pseudo_panel.do                                         
* Task:         run regressions on wage growth on the pseudo-panel                     
* Last change:  26.04.2025                                                               
* Notes:
/*
This file contains the code used to generate the results presented in the following tables and figures:
- Table A.4:
		-- Pseudo-Panel: tab_y_nat_sex2_edu3_age3.txt
*/
******************************************************************************************



******************************************************************************************
*** program setup
******************************************************************************************

version 14.2
clear all
macro drop _all
set linesize 90
set more off
* set trace on
discard
set seed 123456789
*set matsize 2000



******************************************************************************************
*** sample on municipality level by 2 sex, 3 education & 3 age groups: wage sample
******************************************************************************************

*** load working dataset
use "data/wage_region_sex2_edu3_age3.dta", clear

*** set globals
global group_g_y_nat   "Native wage growth by 2 sex, 3 edu. & 3 age groups"

** use different czech shocks
foreach year of numlist 1985/1990 1992/1995 {
global czech_shock_`year' "czshare_92_90_predic_13"
	}

global czech_shock_1991   "czshare_91_90_predic_13"

*** create group dummies: here 2 education groups
egen group_sex2_edu3_age3 = group(female imp_edu age_3)
tab group_sex2_edu3_age3, gen (group_sex2_edu3_age3_)


foreach y of numlist 1987/1995 {

*** 1) basic model: full sample
reg g_y_nat  ${czech_shock_`y'} group_sex2_edu3_age3_*  if year == `y' & (border_imp_13 == 1 | control_imp == 1) [pweight=emp_nat_90*weight_matching], cluster(ao_kreis_imp) noconstant
est store y_nat`y'


*** check sample
dis "Outcome Variable: ${group_g_y_nat}"
dis "Year = `y'"
dis "Sample restriction version: 16-65, full-time employed natives (pers_gr: 101)"
count if e(sample)


********* bootstrap standard errors ***************************************************************
preserve
keep if e(sample)
drop czshare_92_90_predic_13
forval bs = 1/500 {
	di "bootstrap sample `bs'"
	merge m:1 ao_gem_imp using "data/bootstrap/bs_wild_first_92_`bs'.dta", nogenerate
	reg g_y_nat  czshare_92_90_predic_13  group_sex2_edu3_age3_*  if year == `y' & (border_imp_13 == 1 | control_imp == 1) [pweight=emp_nat_90*weight_matching], noconstant
	predict res  if e(sample), res
	predict xb   if e(sample), xb
	gen y = xb + wild * res
	qui reg y  czshare_92_90_predic_13  group_sex2_edu3_age3_*  if year == `y' & (border_imp_13 == 1 | control_imp == 1) [pweight=emp_nat_90*weight_matching], noconstant
	scalar coef`bs' = _b[czshare_92_90_predic_13]
	drop y res xb czshare_92_90_predic_13 wild
}
gen bs = . 
gen coef_g_y_nat_`y' = .
forval bs = 1/500 {
	replace bs = `bs' in `bs'
	replace coef_g_y_nat_`y' = coef`bs' in `bs'
}
keep bs coef_g_y_nat_`y'
keep if bs != .
save "data/bootstrap\pseudo_panel/bs_coef_g_y_nat_`y'.dta", replace
sum coef_g_y_nat_`y'		// std. dev. = std. error
restore

***************************************************************************************************
	}


*** create tables
#delimit ;
global estout_wage "cells(b(star fmt(%9.3f) vacant(-)) se(fmt(%9.3f) par))  
stats(N N_clust r2_a, labels("Observations" "Clusters" "Adjusted R2") layout(@ @ @) fmt(%9.0fc %9.0fc %9.3f))
starlevels(* 0.1 ** 0.05 *** 0.01) varwidth(30)
varlabels(_cons "Constant" czshare_92_90_predic_13 "Share Czechs (92-90, pred.)" czshare_91_90_predic_13 "Share Czechs (91-90, pred.)" 
group_sex2_edu3_age3_1 "group_sex2_edu3_age3_1" group_sex2_edu3_age3_2 "group_sex2_edu3_age3_2" group_sex2_edu3_age3_3 "group_sex2_edu3_age3_3" group_sex2_edu3_age3_4 "group_sex2_edu3_age3_4" 
group_sex2_edu3_age3_5 "group_sex2_edu3_age3_5" group_sex2_edu3_age3_6 "group_sex2_edu3_age3_6" group_sex2_edu3_age3_7 "group_sex2_edu3_age3_7" group_sex2_edu3_age3_8 "group_sex2_edu3_age3_8" 
group_sex2_edu3_age3_9 "group_sex2_edu3_age3_9" group_sex2_edu3_age3_10 "group_sex2_edu3_age3_10" group_sex2_edu3_age3_11 "group_sex2_edu3_age3_11" group_sex2_edu3_age3_12 "group_sex2_edu3_age3_12"
group_sex2_edu3_age3_13 "group_sex2_edu3_age3_13" group_sex2_edu3_age3_14 "group_sex2_edu3_age3_14" group_sex2_edu3_age3_15 "group_sex2_edu3_age3_15" group_sex2_edu3_age3_16 "group_sex2_edu3_age3_16"
group_sex2_edu3_age3_17 "group_sex2_edu3_age3_17" group_sex2_edu3_age3_18 "group_sex2_edu3_age3_18") label
mlabels("W.Gr. 87-90" "W.Gr. 88-90" "W.Gr. 89-90" "W.Gr. 91-90" "W.Gr. 92-90" "W.Gr. 93-90" "W.Gr. 94-90" "W.Gr. 95-90")
prehead(@title) posthead() postfoot(@note) nonumbers collabels(none) style(tab)";
#delimit cr

** Table: Wage growth 
estout  y_nat1987  y_nat1988  y_nat1989  y_nat1991  y_nat1992  y_nat1993  y_nat1994  y_nat1995  ///
using "tables\wage/tab_y_nat_sex2_edu3_age3.txt", $estout_wage replace ///	
title(Native Wage Growth 1987-1995: Pseudo-Panel: ${group_g_y_nat}) ///
note(Notes: Regional approach. * p<0.1, ** p<0.05, *** p<0.01. ///
Data Source: German Social Security Records, border districts and matched control districts, 1987-1995.)


******************************************************************************************
*** end
******************************************************************************************

exit


*========================================================================================*
Comments:
